//弹窗样式
//默认1.5s后消失
function my_alert(b, time, callback) {
	var div = document.createElement('div');
	$("body").append(div);
	var $div = $(div);
	div.className = "tanchuang";
	div.innerHTML = "<span>" + b + "</span>";
	$div.css("opacity", 1);

	$div.stop().animate({
		opacity: 1

	}, 1000, function() {

		$div.stop().animate({
			opacity: 0

		}, 500, function() {
			$div.hide();
			$div.css("opacity", 1);
			$(".tanchuang").remove();
		})

	});

	setTimeout(function() {

		if(typeof(callback) == 'function') {
			callback()
		} else {

		}

	}, time * 1000)
}




   //获取URL上参数
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
        var r = window.location.search.substr(1).match(reg)
        if (r != null) return unescape(r[2])
        return null
    }
    //移除LOADING
    $.RMLOAD = function () {

        (!$('.new-loading').length) || $('.new-loading').remove();
      
    }
    //添加LOADING
    $.ADDLOAD = function () {
        var html = '<div class="new-loading"><ul class="small-loading"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul></div>'
        if (!$('.new-loading').length) {
            $('#app').append(html);
        }
    }

//	前端表单逻辑逻辑验证
//	手机
function iphone(element) {

	if((/^1[3|4|5|7|8]\d{9}$/.test($(element).val()))) {
		return true;
	} else {
		return false;
	}
}
//		密码
function mima(element) {
	var myReg = /^[a-zA-Z0-9]{6,20}$/;
	if(myReg.test($(element).val())) {
		return true;
	} else {
		return false;
	}
}
//		密码
function teshu(element) {
	var myReg = /^[a-zA-Z0-9]{6,20}$/;
	if(myReg.test($(element).val())) {
		return true;
	} else {
		return false;
	}
}
//	重复密码	
function againPassword(element1, element2) {
	var myReg = /^[a-zA-Z0-9]{6,20}$/;
	var value = $(element1).val();
	var value1 = $(element2).val();
	if(myReg.test(value1) && (value1 == value)) {
		return true;
	} else {
		if(value1 != value) {
			my_alert("两次密码不相同，请重新输入")
			return false;
		} else {
			my_alert("请输入六位字母或数字以上组合密码");
			return false;
		}

	}
}

//	身份证
function shenfengzheng(element) {
	var myReg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	if(myReg.test($(element).val())) {
		return true;
	} else {
		return false;
	}
}

//		短信验证码
function yanzheng(element) {
	var value = $(element).val();
	if(value == "" || (/^\s+$/g.test(value))) {

		return false;

	} else {
		return true;
	}

}

//		图形验证码
function yanzheng_num(element) {
	var value = $(element).val();
	if(value == "" || (/^\s+$/g.test(value))) {

		return false;

	} else {
		return true;
	}

}

//		非空判断
function noNull(element) {
	var value = $(element).val();
	if(value == "" || (/^\s+$/g.test(value))) {

		return false;

	} else {
		return true;
	}

}
//		正整数与0
function positive(element) {

	var myReg = /^\d+$/;
	var value = $(element).val();
	if(myReg.test(value)) {

		return true;

	} else {

		return false;
	}

}
function name1(element){
		var myret=/^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]+)*$/;//中文
		var myret1 =/^[a-zA-Z\/ ]{2,20}$/; //英文
		var value = $(element).val();
		if ((myret.test(value))||(myret1.test(value))){
			
			return true;
			
		}else{
			return false;
		}
		
	}
		//授权认证
 	 	window.TOKEN = localStorage.getItem('qy_loginToken')
		if(!window.TOKEN&&location.pathname.indexOf('login')<=-1&&location.pathname.indexOf('mall/list')<=-1&&location.pathname.indexOf('video/list')<=-1&&location.pathname.indexOf('video/info')<=-1){   
		
		location.href="/html/mall/list.html";//返回商品列表

	}
//			使用jQuery的$.ajaxSetup方法可以设置AJAX请求的默认参数选项，当程序中需要发起多个AJAX请求时，则不用再为每一个请求配置请求的参数。
		if(window.TOKEN){
			$.ajaxSetup({
				aysnc: false , // 默认同步加载  
				headers:{
					  	Authorization:'Basic '+$.base64.encode(window.TOKEN)
				}

			})
		}
		
//判断是否为微信
function is_weixin() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/micromessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}		
		//登录错误跳回登录页
function Backlog(backUrl) {
    if (is_weixin()) {

        var backUrls=backUrl?backUrl:''
        window.location.href = "/WeiXin/Login"+backUrls?('?backUrl='+backUrls):''
    } else {
        window.location.href = "/Html/Member/Login.html"
    }
}
if(window.TOKEN&&location.pathname.indexOf('login')<=-1&&location.pathname.indexOf('mall/list')<=-1&&location.pathname.indexOf('video/list')<=-1&&location.pathname.indexOf('video/info')<=-1){   
		
		bottomMessage();

	}
function bottomMessage(){	//判断授权			
				var parsom={};
				    $.ajax({
                    url: "/Api/v1/Member/MessageCount",
                    dataType: "json",
                    type: "get",
                    data:parsom,
                    success: function (data) {
                    		
	                    	if(data.returnCode == '200'){
	                    		
	                    		$(".cartNumBox").html(data.data.CartCount)
	                    		
	                    	}else{
	                    		
	                    		my_alert(data.msg);
	                    		if(data.returnCode == '401'){
	                    			my_alert(data.msg,1.5,function(){
	                    				
	                    				localStorage.clear();
	                    				location.href="/html/mall/list.html";//返回商品列表
	                    			});
	                    		
	                    		}else{
	                    			my_alert(data.msg)
	                    		}
	                    		
	                    	}
                    	
                    	}
                    ,error:function(xh,yh,error){
                    	my_alert(error);
                    	
                    }
				})	
			}			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
	